import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.font_manager import FontProperties
import numpy as np
import pandas as pd 
#loc:文件所在位置
#title:图的标题
#size:大小
#tiem:步数
#outname:图的文件名


def paint_threedata(data,outname):
    df_pic1 = data
    fig = plt.figure(figsize=(8, 6), facecolor='ivory')
    ax1 = fig.add_subplot(111)
    mpl.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
    font = FontProperties()  # 字体类
    font.set_family('serif')
    font.set_name('Times New Roman')
    font.set_style('italic')
    # ax1.set_title(title, fontproperties=font, color='green', size=18, pad=10)
    plt.rc('font', family='Times New Roman')



    x1 = df_pic1['time']
    y1 = df_pic1['kinetic']
    y2 = df_pic1['strain']
    y3 = df_pic1['total']
    ax1.set_xlabel('time (s)', color='green', size=16) #横坐标名称
    ax1.set_ylabel("energy (mJ)", color='blue', size=16) #纵坐标名称

    l1 = ax1.plot(x1, y1, color="blue", label="kinetic", marker=".", markevery=20)
    l2 = ax1.plot(x1, y2, color="green", label="strain", marker="x", markevery=20)
    l3 = ax1.plot(x1, y3, color="red", label="total", marker="^", markevery=20)
    ax1.tick_params(axis='y',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='blue',  # 颜色
                   labelsize=12,  # 标签字体大小
                   )

    ax1.tick_params(axis='x',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='green',  # 颜色
                   labelsize=12,  # 标签字体大小
                   top=True,
                   left=True,
                   labeltop=False,
                   labelright=True
                   )                                        #设置刻度格式

    lt = l1 + l2 + l3
    labs1 = [l.get_label() for l in lt]
    ax1.legend(lt, labs1, loc='best')

    fig.savefig(outname, transparent=True,dpi = 600)
def paint_fourdata(data2,data3,data4,data5,outname):


    fig = plt.figure(figsize=(8, 6), facecolor='ivory')
    ax1 = fig.add_subplot(111)
    mpl.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
    font = FontProperties()  # 字体类
    font.set_family('serif')
    font.set_name('SimHei')
    font.set_style('italic')
    # ax1.set_title(title, fontproperties=font, color='green', size=18, pad=10)

    x1 = data2['time']
    y1 = data2['stress']
    y2 = data3['stress']
    y3 = data4['stress']
    y4 = data5['stress']  #请输入你需要的数据#请输入你需要的数据
    ax1.set_xlabel('time (s)', color='green', size=16) #横坐标名称
    ax1.set_ylabel("stress(MPa)", color='blue', size=16) #纵坐标名称

    l1 = ax1.plot(x1, y1, color="blue", label="25mm", marker=".", markevery=20)
    l2 = ax1.plot(x1, y2, color="green", label="50mm", marker="x", markevery=20)
    l3 = ax1.plot(x1, y3, color="red", label="100mm", marker="^", markevery=20)
    l4 = ax1.plot(x1, y4, color="orange", label="150mm", marker="*", markevery=20)
    ax1.tick_params(axis='y',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='blue',  # 颜色
                   labelsize=12,  # 标签字体大小
                   )

    ax1.tick_params(axis='x',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='green',  # 颜色
                   labelsize=12,  # 标签字体大小
                   top=True,
                   left=True,
                   labeltop=False,
                   labelright=True
                   )                                        #设置刻度格式

    lt = l1 + l2 + l3 +l4
    labs1 = [l.get_label() for l in lt]
    ax1.legend(lt, labs1, loc='best')

    fig.savefig(outname, transparent=True,dpi = 600)

def paint_threedata2(data6,data7,data8,outname):

    fig = plt.figure(figsize=(8, 6), facecolor='ivory')
    ax1 = fig.add_subplot(111)
    mpl.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
    font = FontProperties()  # 字体类
    font.set_family('serif')
    font.set_name('Times New Roman')
    font.set_style('italic')
    # ax1.set_title(title, fontproperties=font, color='green', size=18, pad=10)
    plt.rc('font', family='Times New Roman')



    x1 = data6['time']
    y1 = data6['stress']
    y2 = data7['stress']
    y3 = data8['stress']
    ax1.set_xlabel('time (s)', color='green', size=16) #横坐标名称
    ax1.set_ylabel("stress(MPa)", color='blue', size=16) #纵坐标名称

    l1 = ax1.plot(x1, y1, color="blue", label="30mm", marker=".", markevery=20)
    l2 = ax1.plot(x1, y2, color="green", label="60mm", marker="x", markevery=20)
    l3 = ax1.plot(x1, y3, color="red", label="90mm", marker="^", markevery=20)
    ax1.tick_params(axis='y',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='blue',  # 颜色
                   labelsize=12,  # 标签字体大小
                   )

    ax1.tick_params(axis='x',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='green',  # 颜色
                   labelsize=12,  # 标签字体大小
                   top=True,
                   left=True,
                   labeltop=False,
                   labelright=True
                   )                                        #设置刻度格式

    lt = l1 + l2 + l3
    labs1 = [l.get_label() for l in lt]
    ax1.legend(lt, labs1, loc='best')

    fig.savefig(outname, transparent=True,dpi = 600)
def paint_threedata3(data9,outname):

    fig = plt.figure(figsize=(8, 6), facecolor='ivory')
    ax1 = fig.add_subplot(111)
    mpl.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
    font = FontProperties()  # 字体类
    font.set_family('serif')
    font.set_name('Times New Roman')
    font.set_style('italic')
    # ax1.set_title(title, fontproperties=font, color='green', size=18, pad=10)
    plt.rc('font', family='Times New Roman')



    x1 = data9['time']
    y1 = data9[30]
    y2 = data9[60]
    y3 = data9[90]
    ax1.set_xlabel('time (s)', color='green', size=16) #横坐标名称
    ax1.set_ylabel("stress(MPa)", color='blue', size=16) #纵坐标名称

    l1 = ax1.plot(x1, y1, color="blue", label="30mm", marker=".", markevery=20)
    l2 = ax1.plot(x1, y2, color="green", label="60mm", marker="x", markevery=20)
    l3 = ax1.plot(x1, y3, color="red", label="90mm", marker="^", markevery=20)
    ax1.tick_params(axis='y',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='blue',  # 颜色
                   labelsize=12,  # 标签字体大小
                   )

    ax1.tick_params(axis='x',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='green',  # 颜色
                   labelsize=12,  # 标签字体大小
                   top=True,
                   left=True,
                   labeltop=False,
                   labelright=True
                   )                                        #设置刻度格式

    lt = l1 + l2 + l3
    labs1 = [l.get_label() for l in lt]
    ax1.legend(lt, labs1, loc='best')

    fig.savefig(outname, transparent=True,dpi = 600)

def paint_threedata3(data10,outname):

    fig = plt.figure(figsize=(8, 6), facecolor='ivory')
    ax1 = fig.add_subplot(111)
    mpl.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
    font = FontProperties()  # 字体类
    font.set_family('serif')
    font.set_name('Times New Roman')
    font.set_style('italic')
    # ax1.set_title(title, fontproperties=font, color='green', size=18, pad=10)
    plt.rc('font', family='Times New Roman')



    x1 = data10['time']
    y1 = data10[30]
    y2 = data10[50]
    y3 = data10[70]
    ax1.set_xlabel('time (s)', color='green', size=16) #横坐标名称
    ax1.set_ylabel("stress(MPa)", color='blue', size=16) #纵坐标名称

    l1 = ax1.plot(x1, y1, color="blue", label="30mm", marker=".", markevery=20)
    l2 = ax1.plot(x1, y2, color="green", label="50mm", marker="x", markevery=20)
    l3 = ax1.plot(x1, y3, color="red", label="70mm", marker="^", markevery=20)
    ax1.tick_params(axis='y',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='blue',  # 颜色
                   labelsize=12,  # 标签字体大小
                   )

    ax1.tick_params(axis='x',  # 只设置x轴刻度
                   direction='in',  # 刻度线朝内
                   length=3, width=3,  # 长度和宽度
                   colors='green',  # 颜色
                   labelsize=12,  # 标签字体大小
                   top=True,
                   left=True,
                   labeltop=False,
                   labelright=True
                   )                                        #设置刻度格式

    lt = l1 + l2 + l3
    labs1 = [l.get_label() for l in lt]
    ax1.legend(lt, labs1, loc='best')

    fig.savefig(outname, transparent=True,dpi = 600)
# data1 = pd.read_excel('100-energy.xlsx')
# paint_threedata(data1,'energy.jpg')
#
# data2 = pd.read_excel('25-stress.xlsx')
# data3 = pd.read_excel('50-stress.xlsx')
# data4 = pd.read_excel('100-stress.xlsx')
# data5 = pd.read_excel('150-stress.xlsx')
#
# paint_fourdata(data2,data3,data4,data5,'stress.jpg')
# data6 = pd.read_excel('100-stress-Gai30.xlsx')
# data7 = pd.read_excel('100-stress.xlsx')
# data8 = pd.read_excel('100-stress-Gai90.xlsx')
# paint_threedata2(data6,data7,data8,'Gaiban.jpg')
#
# data9 = pd.read_excel('100-stress-up.xlsx')
# paint_threedata3(data9,'stress-up.jpg')

data10 = pd.read_excel('100-stress-oca1.xlsx')
paint_threedata3(data10,'stress-oca.jpg')